// 作者:于大明
// 职责：处理业务逻辑
//------------------------------mock数据引入---------------------------
import myCardBodyMock from './my-card-body_mock.js';
import citys from '/lib/city/city.js';

let mixin = {
	// 负责程序中需要进行set的数据 就是页面交互需要改的数据 比如点击checkbox 需要设置true false 和存放ajax的输入输出 (尽量少去定义data里面的属性 多用computed或者filters或者组件进行处理) 
	// 1 能不能在页面单行代码实现
	// 2 能不能不用data methods去实现这个功能
	data() {
		return {
			dateDialog: false,
			pickHeights: myCardBodyMock.pickHeights,
			areas: myCardBodyMock.areas,
			eduTypes: this.$cw.EduTypes,
			houseCarTypes: this.$cw.HouseCarTypes,
			marryTypes: this.$cw.MarryTypes,
			tableTrs: myCardBodyMock.tableTrs,
			sexTypes: this.$cw.SexTypes,
			pickPop: false,
			citys: citys,
			map: {
				text: 'name',
				value: 'id'
			}
		};
	},
	// 负责和页面事件进行交互
	methods: {
		async chooseWxImage() {
			let imgUrl = await this.$cw.chooseGetFilePath();
			if (imgUrl) {
				this.wxUserForm.userInfoWxCodeUrl =imgUrl;
			}
		},
		pickShow() {
			this.pickPop = true;
			this.$refs.picker[0].show();
		},
		async delImg(index) {
			let res = await this.$cw.showConfirm("确认要删除吗");
			if (res) {
				let imgList = (this.wxUserForm.wxUserInfoImgUrls.split(','));
				imgList.splice(index, 1);
				this.wxUserForm.wxUserInfoImgUrls = imgList.join(',');
			}
		},
		async chooseImage() {
			let imgUrl = await this.$cw.chooseGetFilePath();
			if (imgUrl) {
				let imgList = this.wxUserForm.wxUserInfoImgUrls.split(',').filter(x => x);
				imgList.push(imgUrl);
				this.wxUserForm.wxUserInfoImgUrls = imgList.join(',');
			}

			// uni.chooseImage({
			// 	count: 3, // 默认9
			// 	sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			// 	sourceType: ['album'], //从相册选择
			// 	success: (res) => {
			// 		if (imgList != 0) {
			// 			imgList = imgList.concat(res.tempFilePaths);
			// 		} else {
			// 			imgList = res.tempFilePaths;
			// 		}

			// 	}
			// });
		},
		viewImage(url) {
			uni.previewImage({
				urls: this.wxUserForm.wxUserInfoImgUrls.split(","),
				current: url
			});
		},
	},
	// 不要set的数据 统一用computed实现(能用computed 实现的 尽量用他实现 不要用data和method处理) 有返回值的不需要传参的method用computed实现 
	computed: {
		allCalKeys(){
			const keys= Object.keys(this.wxUserForm).filter(x=>x.startsWith('isShow')&&x!='isShowWxUserInfoNickName'&&x!='isShowWxUserInfoImgUrls');
			return keys;
		},
		isAllChecked(){
			if(this.allCalKeys.length>0){
				const isAll= this.allCalKeys.every(x=>parseInt(this.wxUserForm[x]));
				return isAll;
			}
		},
		item() {
			// return this._.cloneDeep(this.inputItem);
		},
	},
	// 负责格式化数据 有返回值的需要传参的method 用filters实现
	filters: {
		// 多个参数filter 调用  {{day|weekDayFmt(getStudentListIn.month)}} filter filter后缀加上Fmt  vue3参考: http://knowledge.whcewei.com/CodeKnowledge/Detail-91D4B057-821A-4A0C-96E5-C0BC8CDDDC9C.aspx
		//weekDayFmt(day, yearMonth) {
		//    var weekDay = moment(yearMonth + "-" + day).day();
		//    var weekObj = { 1: "一", 2: "二", 3: "三", 4: "四", 5: "五", 6: "六", 0: "日" };
		//    return weekObj[weekDay];
		//},
	},
	// 负责数据变化后需要和接口交互
	watch: {
		//"currentStore.storeId": {
		//    handler(val, oldval) {
		//        if (val) {
		//        }
		//    },
		//    deep: true,
		//    immediate: true
		//}
	},
}
export default mixin;